import Big from 'big.js'
export const  lpMap = {
    "0x87a0183e4460D313257627B4cBB4E59cfcB7F7bb"  :["0x2E51b6f3181b342d098B1a939Ae1944ED6768fd4","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x0eD7e52944161450477ee417DE9Cd3a859b14fD0"  :["0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16"  :["0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
    "0x16b9a82891338f9bA80E2D6970FddA79D1eb0daE"  :["0x55d398326f99059ff775485246999027b3197955","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"], 
}

async function getBanlanceOf(instance,address){ return instance.methods.balanceOf(address).call({from:window.addr, }) } 
async function getRatio(web3,address){ var arr   = await web3.Selexchange(address); return Big(arr[0]).div(Big(arr[1])) }  
async function getRatioBNB(web3){  
    var arr = await web3.Selexchange2("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c","0x55d398326f99059ff775485246999027b3197955")
     return  Big(arr[1]).div(Big(arr[0]))
}  

async function getRatioDemon(web3){  
    var arr = await web3.Selexchange2("0x2E51b6f3181b342d098B1a939Ae1944ED6768fd4","0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c")
     return  Big(arr[1]).div(Big(arr[0]))
}  

export const  calc = async (data,web3)=>{ 
    console.log(data)
    calcLP(data,web3)

}

export const  calcSingle = async (data,web3)=>{ 
    console.log(data)

}

export const  calcLP = async (data,web3)=>{ 
    console.log(data,"计算一下这里的汇率常量")
    var amount = window.Web3.utils.toBN("1000000000000000000")
    var bnb = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"
    var usdt = "0x55d398326f99059ff775485246999027b3197955"
    var e = "0x0eD7e52944161450477ee417DE9Cd3a859b14fD0" 
    var map = {
        demon:"0x2E51b6f3181b342d098B1a939Ae1944ED6768fd4",
        bnb:"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
        usdt:"0x55d3983326f99059ff775485246999027b3197955",
        cake:"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", 
    } 

    const res = await Promise.all( [web3.getAmountsOut(amount,[lpMap[e][0],map.bnb]).call(window.sender),web3.getAmountsOut(amount,[bnb,usdt]).call(window.sender) ])
    console.log("res",res) 
    console.log("汇率a",Big(res[0][1]).div(Big(res[0][0])).toString())
    
}

/*
data.lpList.map(async (e,i)=>{
    console.log(lpMap[e][0],lpMap[e][1])
    if(i < -1 ){
        var arr = [web3.getAmountsOut(amount,[lpMap[e][0],bnb]).call(window.sender),web3.getAmountsOut(amount,[bnb,usdt]).call(window.sender) ]
        const res = await Promise.all(arr)
        console.log("res",res)
    }  
})
*/